package skdao

import (
	"Cgo/front/models"
	"Cgo/global"
)

type scDao struct{}

var ScDao = scDao{}

func (s scDao) GetFavoriteBooks(userId int) ([]models.SkBook, error) {
	var results []models.SkBook

	// 执行数据库查询
	if err := global.DB.Table("sk_book as b").
		Select("b.*").
		Joins("LEFT JOIN sk_shoucang as sc ON sc.bookId = b.bookId").
		Where("sc.id = ?", userId).
		Find(&results).Error; err != nil {
		return nil, err
	}

	return results, nil
}
